package controller;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import server.FirewallManager;
import server.FirewallSession;
//import server.FirewallSession;
import server.InvalidLoginException;


public class controllerFunc {
	public static  FirewallSession PerformLogin(String ip, String prmUserName, String prmPassword )
	throws InvalidLoginException,Exception
	{
		String host = null;
		if ( ( ip != null ) && (! ip.equals("")) ){
			host = ip;
		}
		
		//FirewallSession session =new FirewallSession ();
		
		System.out.println("Connecting to " + ( host != null ? host:"localhost" ) +" as "+prmUserName +"..\n");
		Registry registry = LocateRegistry.getRegistry(host);
		FirewallManager stub = (FirewallManager)
		registry.lookup("FirewallManager");

		FirewallSession session =stub.login(prmUserName, prmPassword);
		if (session.isExpert()) {
			System.out.println("Woohoo! I'm an expert\n");
		} else {
			System.out.println("Oh man, I'm simple!\n");
		}
		return session; 
		
	}
}
